package znbkTestPaperXtfx.saveDiagnosticReportInfo;

import com.example.lancooznbk.view.base.ILoadDataPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperRdqh.activity.WeekAscensionPaperActivity;
import znbkTestPaperXtfx.activity.SystemReviewPaperActivity;

/**
 * Created by Administrator on 2018\4\3 0003.
 */

public class SaveDiagnosticReportPresenter implements ILoadDataPresenter {

    private ILoadPaperView view;
    private int ModelFrom;

    public SaveDiagnosticReportPresenter(ILoadPaperView view, int modelFrom) {
        this.view = (ILoadPaperView) view;
        this.ModelFrom = modelFrom;
    }

    @Override
    public void getData(boolean isShowing) {
            HttpOnNextListener<SaveDiagnosticReportResult> httpOnNextListener = new HttpOnNextListener<SaveDiagnosticReportResult>() {

            @Override
            public void onNext(SaveDiagnosticReportResult saveDiagnosticReportResult) {

                if(saveDiagnosticReportResult.isResult()){
                    ToastUtils.showShort("提交练习报告成功");
                    view.updatingReportResult(true);
                }else{
                    view.updatingReportResult(false);
                    ToastUtils.showShort("提交练习报告失败! 错误码"+saveDiagnosticReportResult.isResult());
                }

            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                ToastUtils.showShort("提交练习报告失败!");
            }
        };

        SaveDiagnosticReportApi api = null;
        if(ModelFrom== ZnbkPaperDef.FROM_SYSTEM_REVIEW) {
            api = new SaveDiagnosticReportApi(httpOnNextListener, (SystemReviewPaperActivity) view);
            api.setmSaveDiagnosticReportEntity(SaveDiagnosticReportEntityModel.SaveDiagnosticReportEntityXtfx());
        }else if(ModelFrom== ZnbkPaperDef.FROM_WEEK_ASCENSION) {
            api = new SaveDiagnosticReportApi(httpOnNextListener, (WeekAscensionPaperActivity) view);
            api.setmSaveDiagnosticReportEntity(SaveDiagnosticReportEntityModel.SaveDiagnosticReportEntityRdqh());
        }

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {

    }

}